<?php 
require_once 'ckLogin.php';
require_once 'init.php';
require_once 'dbClasses'.DIRECTORY_SEPARATOR.'config.php';
require_once 'dbClasses'.DIRECTORY_SEPARATOR.'dbConn.php';
$parentid = !empty($_GET['parentid'])?$_GET['parentid']:1;

$db = new dbConn();
if(!empty($_GET['act'])){
	$act = $_GET['act'];
	switch ($act) {
		case 'del':
			if (!empty($_GET['id'])){
				$db->sql = "DELETE FROM buttomlinks WHERE id = ".$_GET['id'];
				$db->doExecute();
			}
			break;
		case 'insertLink':
			if(strtoupper($_SERVER['REQUEST_METHOD'])=='POST'){
				$db->sql = "INSERT INTO buttomlinks(`name`,address,css,parentid,level,`order`) VALUES('{$_POST['name']}','".str_replace(' ', '', trim($_POST['url']) )."','{$_POST['css']}',{$parentid},2,{$_POST['sort']})";
				$db->doExecute();
			}
			break;
		case 'edit':
			if(strtoupper($_SERVER['REQUEST_METHOD'])=='POST'){
				$db->sql="UPDATE buttomlinks SET name='".$_POST['linkName']."',address='".str_replace(' ', '', trim($_POST['linkUrl']) )."',css='".$_POST['linkCSS']."',`order`=".$_POST['linkSort']." WHERE id=".$_POST['linkID'];
				$db->doExecute();
			}
	}
	
}
$db->sql = "SELECT * FROM buttomlinks WHERE parentid = {$parentid} ORDER BY `order` ASC ";
$buttomlinks = $db->doResultList2();
$db->sql = "SELECT * FROM buttomlinks WHERE parentid = 0 ORDER BY `order` ASC ";
$linksCate = $db->doResultList2();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo APPLICATION;?></title>
<!--                       CSS                       -->
<!-- Reset Stylesheet -->
<link rel="stylesheet" href="resources/css/reset.css" type="text/css" media="screen" />
<!-- Main Stylesheet -->
<link rel="stylesheet" href="resources/css/main.css" type="text/css" media="screen" />
<!-- Invalid Stylesheet. This makes stuff look pretty. Remove it if you want the CSS completely valid -->
<link rel="stylesheet" href="resources/css/invalid.css" type="text/css" media="screen" />

<!-- jQuery -->
<script type="text/javascript" src="resources/scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(function($) {
	$("#insert-new-link-button").click(function(){
		$("#insert-new-goods-tr").show();
	});
	$("#insert-new-link-submit").click(function(){
		$("form").submit();
	});
	$(".deleteUser").click(function(){
		if(!confirm("是否将此链接删除?")){
			return false;
		}
	});
	$(".editButton").click(function(){
		//var goodsID = $(this).parents("tr").find(".radio").val();
		// linkID linkName linkUrl linkSort
		var linkID = $(this).parents("tr").children("td").eq(0).text();
		var linkName = $(this).parents("tr").children("td").eq(1).text();
		var linkUrl = $(this).parents("tr").children("td").eq(2).text();
		var linkSort = $(this).parents("tr").children("td").eq(4).text();
		var linkCSS = $(this).parents("tr").children("td").eq(3).text();
		$("#linkName").val(linkName);
		$("#linkUrl").val(linkUrl);
		$("#linkSort").val(linkSort);
		$("#linkID").val(linkID);
		$("#linkCSS").val(linkCSS);
		//$("#goodsPrice").val(price);
		//alert(url);
		$("#message_click").click();
	});
	$(".success").ajaxSuccess(function(evt, request, settings){
		$(this).show();
	});
	$(".error").ajaxError(function(event,request, settings){
		$(this).show();
	});
});
</script>
<!-- jQuery Configuration -->
<script type="text/javascript"
	src="resources/scripts/simpla.jquery.configuration.js"></script>
<!-- Facebox jQuery Plugin -->
<script type="text/javascript" src="resources/scripts/facebox.js"></script>
<!-- jQuery WYSIWYG Plugin -->
<script type="text/javascript" src="resources/scripts/jquery.wysiwyg.js"></script>

</head>

<body>
	<div id="body-wrapper">
		<!-- Wrapper for the radial gradient background -->
		<a href="#messages" rel="modal" id="message_click"></a>
		<div id="messages" style="display: none;">
			<!-- Messages are shown when a link with these attributes are clicked: href="#messages" rel="modal"  -->

			<p>
				<strong>简短描述输入及修改</strong>
			</p>
			<form action="?act=edit" method="post" style="text-align: right;">
			<!-- goodsID goodsPic goodsTitle goodsUrl goodsPrice -->
				<fieldset>
					名称：
					<input class="text-input " type="text" id="linkName" name="linkName" style="width: 310px;"/><br />
					链接：
					<input class="text-input " type="text" id="linkUrl" name="linkUrl" style="width: 310px;"/><br />
					css：
					<input class="text-input " type="text" id="linkCSS" name="linkCSS" style="width: 310px;"/><br />
					排序：
					<input class="text-input " type="text" id="linkSort" name="linkSort" style="width: 310px;"/><br />
					
					<input class="text-input " type="hidden" id="linkID" name="linkID" style="width: 310px;"/><br />
					
					<input class="button" type="submit" value="修改" />
					<a href="javascript:void(0);" onclick="$(this).parents('#facebox').hide();">关闭</a>
				</fieldset>
			</form>

		</div>
		<!-- End #messages -->
		<div id="main-content">
			<!-- Page Head -->
			<h2>欢迎使用<?php echo APPLICATION;?>管理后台</h2>
			<p id="page-intro">用户管理</p>

			<div class="clear"></div>
			<!-- End .clear -->

			<div class="content-box">
				<!-- Start Content Box -->

				<div class="content-box-header">

					<h3>用户管理</h3>

					<div class="clear"></div>

				</div>
				<!-- End .content-box-header -->

				<div class="content-box-content">

				<!-- Start Notifications -->
				
				<div class="notification success png_bg" style="display: none;">
					<a href="#" class="close"><img
						src="resources/images/icons/cross_grey_small.png"
						title="Close this notification" alt="close" /></a>
					<div>
						修改成功
					</div>
				</div>
				
				<div class="notification error png_bg" style="display: none;">
					<a href="#" class="close"><img
						src="resources/images/icons/cross_grey_small.png"
						title="Close this notification" alt="close" /></a>
					<div>
					修改失败
					</div>
				</div>
				
				<!-- End Notifications -->
				
					<div class="tab-content default-tab" id="tab1">
						<!-- This is the target div. id must match the href of this div's tab -->
						css例子 ：     color:#f043c1;
						<table>
							<thead>
								<tr>
									<th colspan="6">
									<?php foreach ($linksCate as $key=>$item):?>
									<a href="?parentid=<?php echo $item['id']?>" style="<?php if($item['id']==$parentid) echo "color:black;";?>"><?php echo $item['name'];?></a>&nbsp;&nbsp;&nbsp;&nbsp;
									<?php endforeach;?>
									</th>
								</tr>
								<tr>
									<th style="width: 5%">编号</th>
									<th style="width: 10%">命名</th>
									<th >链接</th>
									<th style="width: 15%">CSS</th>
									<th style="width: 5%">排序</th>
									<th style="width: 5%">操作</th>
								</tr>
							</thead>

							<tbody>
							<?php if(count($buttomlinks)>0):?>
							<?php foreach ($buttomlinks as $key=>$item):?>
								<tr>
									<td><?php echo $item['id'];?></td>
									<td><?php echo $item['name'];?></td>
									<td><?php echo $item['address'];?></td>
									<td><?php echo $item['css'];?></td>
									<td><?php echo $item['order'];?></td>
									<td>
										<!-- <a href="userAdd.php?id=<?php echo $item['id'];?>">修改</a> -->
										<a class="editButton" href="javascript:void(0);">修改</a><br />
										<a class="deleteUser" href="?id=<?php echo $item['id'];?>&act=del">删除</a>
									</td>
								</tr>
							<?php endforeach;?>
							<?php else:?>
								<tr style="font-size: 50px;text-align: center; font-weight: bold;"><td colspan="5" style="text-align: center;">没有链接</td></tr>
							<?php endif;?>
								<tr id="insert-new-goods-tr" style="display: none;">
								<form method="post" action="?act=insertLink&parentid=<?php echo $parentid;?>&">
									<td></td>
									<td><input type="text" name="name"/></td>
									<td><input type="text" name="url" style="width: 400px;"/></td>
									<td><input type="text" name="css" /></td>
									<td><input type="text" name="sort" style="width: 30px;" value="1"/></td>
									<td><a href="javascript:void(0);" id="insert-new-link-submit">添加</a></td>
								</form>
								</tr>
							</tbody>

						</table>

					</div>
					<!-- End #tab2 -->
					<br style="clear: both;"/>
					<a href="javascript:void(0);" id="insert-new-link-button">链接添加</a>
				</div>
				<!-- End .content-box-content -->

			</div>
			<!-- End .content-box -->

			<div class="clear"></div>

			<div id="footer">
				<small> <!-- Remove this notice or replace it with whatever you want -->
					&#169; Copyright 2009 Your Company | Powered by <a
					href="http://themeforest.net/item/simpla-admin-flexible-user-friendly-admin-skin/46073">Simpla
						Admin</a> | <a href="#">Top</a>
				</small>
			</div>
			<!-- End #footer -->

		</div>
		<!-- End #main-content -->

	</div>
</body>


<!-- Download From www.exet.tk-->
</html>
